const express = require('express')
const app = express()
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
// 导入路由
const address = require('../router/address/address')
const cart = require('../router/cart/cart')
const shop = require('../router/shop/shop')
const search = require('../router/search/search')
const order = require('../router/order/order')
const Backend = require('../router/Backend/Backend')
const user = require('../router/user/user')

// 配置跨域
app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method')
    res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
    res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
    next();
});

app.use('/', address)
app.use('/', cart)
app.use('/', shop)
app.use('/', search)
app.use('/', order)
app.use('/', Backend)
app.use('/', user)
app.listen(3000, () => {
    console.log('服务已启动');
})

